package org.example.demo3.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.demo3.dto.SearchrecordDto;
import org.example.demo3.enity.searchrecord;
import org.example.demo3.mapper.SearchrecordMapper;
import org.example.demo3.service.SearchRecordService;
import org.example.demo3.untils.BeanCopyUtils;
import org.example.demo3.vo.searchRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
@Service
public class SearchRecordServiceImpl extends ServiceImpl<SearchrecordMapper, searchrecord> implements SearchRecordService {
    @Autowired
    private SearchrecordMapper searchrecordMapper;


    @Override
    public List<searchRecordVO> find(SearchrecordDto searchrecorddto){
        QueryWrapper<searchrecord> wrapper = new QueryWrapper<>();
        wrapper.eq("uid", searchrecorddto.getUid());
        List<searchrecord> searchrecord = searchrecordMapper.selectList(wrapper);
        return BeanCopyUtils.copyBeanList(searchrecord, searchRecordVO.class);
    }

    @Override
    public void save(SearchrecordDto searchrecorddto){
          BeanCopyUtils.copyBean(searchrecorddto, searchrecord.class);
    }
    @Override
    public Boolean cleanSearchRecord(SearchrecordDto searchrecorddto) {
        QueryWrapper<searchrecord> wrapper = new QueryWrapper<>();
        wrapper.eq("uid", searchrecorddto.getUid());
        boolean remove = this.remove(wrapper);
        return remove;
    }
}
